/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fusiondata;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Administrator
 */
public class TestAccess {

private final static String DBDRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
private final static String DBURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=";
private final static String DBUSER ="";
private final static String DBPASSWORD ="";
private static Connection conn = null;


public TestAccess(){
    System.out.println("开始连接");
try {
Class.forName(DBDRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(DBURL+"c:\\test.mdb");
//Statement st = conn.createStatement();
//ResultSet  rs = st.executeQuery("select * from user ");
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getTables(null, null, null,new String[] { "TABLE" });
   while (rs.next()) {
     System.out.println("表名：" + rs.getString(3));
     System.out.println("表所属用户名：" + rs.getString(2));
     System.out.println( rs.getString(1));
     System.out.println("------------------------------");
   }
if(conn != null)System.out.println("连接成功");
} catch (SQLException e) {
    System.out.println(e.getMessage());
e.printStackTrace();
}
}

public Connection getConnection(){

if(conn==null)
{
try
{
    System.out.println("进入连接");
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
System.out.println("连接成功");
return conn ;

}
catch (Exception e)
{
    System.out.println("连接失败");
e.printStackTrace();

}

}
return conn;
}
     public static void main(String[] args) {
         new TestAccess();

    }
}
